<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>骨医快线</title>
	<link href="../../css/mui.plus.css" rel="stylesheet" />	
	<style>
		.oe-login input {
			text-align: left;
			border-bottom: 1px solid #ccc;
			background-color: #fff;
		}
		button.disabled {
		    border: 1px solid #ccc!important;
		    color: #999!important;
		    background: #fff!important;
		}
	</style>
</head>
<body>
	<span class="mui-action-back" style="position: absolute;right: 20px;top: 20px;color: #999;">关闭</span>
	<div class="mui-content oe-login">
		<form class="mui-input-group">
			<div class="mui-input-row">
				<input id="telInp" type="tel" class="mui-input-clear" placeholder="输入手机号" maxlength="11">
			</div>
			<div class="oe-webkit-box" style="margin-top: 15px;">
				<input id="pinInp" type="tel" placeholder="输入验证码" maxlength="6" style="padding-right: 20px;">
				<button id="pinBtn" type="button" class="mui-btn mui-btn-primary" onclick="return false;">获取验证码</button>&nbsp;&nbsp;
			</div>
				
			<button id="nextBtn" type="button" class="mui-btn mui-btn-primary oe-btn-block disabled" onclick="return false;" style="margin-top: 15px;" disabled="">下一步</button>&nbsp;&nbsp;
		</form>
	</div>
		
	<script src="../../js/mui.min.js"></script>
	<script src="../../js/app.js"></script>
	<script src="../../js/lib/template.js"></script>
	<script type="text/javascript">
		(function($,doc){
		var telInp =doc.getElementById('telInp');
		var pinInp = doc.getElementById('pinInp');
		var pinBtn = doc.getElementById("pinBtn");
		var nextBtn = doc.getElementById("nextBtn");
		var login = app.login;
		
  		$.plusReady(function(){
  			plus.screen.lockOrientation('portrait-primary');
  			
  			// 事件装载
  			// ==========================================================
  			
  			window.addEventListener('start', function(){
  				telInp.value = pinInp.value = '';
  			});
  			
  			pinInp.addEventListener('input', function(){
  				var pinInfo = {
					tel : telInp.value,
					pin : pinInp.value
				};
				login.checkPin(pinInfo, function(msg){
					if(msg && typeof msg === 'string'){
//						plus.nativeUI.toast(msg);
						return;
					}else if(msg && !msg.data){
						return $.toast('该号码尚未注册')
					}
					nextBtn.removeAttribute('disabled');
					nextBtn.classList.remove('disabled');
				});
			})
  			
  			
  			// Button下一步
			$('.mui-content').on('tap', '#nextBtn', function(event) {
				var pinInfo = {
					tel : telInp.value,
					pin : pinInp.value
				};
				login.checkPin(pinInfo, function(msg){
//					if(msg && typeof msg === 'string'){
//						plus.nativeUI.toast(msg);
//						return;
//					}else if(msg && !msg.data){
//						return $.toast('该号码尚未注册')
//					}
					
					
					//打开密码设置页面    
				  	$.openWindow({
				  		url: 'reset.html',
				  		show: {
							aniShow: 'slide-in-bottom'
						},
						waiting : {
							autoShow : false
						},
						extras:{
					      	account : telInp.value,
					      	drId: msg.data.dr_id
					    }
				  	});
				});
				
			});  
			
			// Button 验证码
			$('.mui-content').on('tap','#pinBtn',function(e) {
				var tel = telInp.value;
				resendTime(document.getElementById("pinBtn"));
//				resendTime(this);
				login.getPin(tel, function(err){
					if(err){
						plus.nativeUI.toast(err);
						return; 
					}
				});
			});
			
			// 验证码60s倒计时
			var wait = 60; 
			function resendTime(o) {  
		        if (wait == 0) {  
		            o.removeAttribute("disabled");            
		            o.innerHTML="获取验证码";  
		            wait = 60;  
		        }else {  
		            o.setAttribute("disabled", true);  
		            o.innerHTML="重新发送(" + wait + ")";  
		            wait--;  
		            setTimeout(function() {  
		                resendTime(o)  
		            },1000)}}; 
		            
		})}(mui,document));
	</script>
</body>
</html>